﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HouseManager.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>房屋管理</title>
    <style>
        #GridView1 {
            text-align: center;
            width: 80%
        }
    </style>
    <script src="jquery-1.10.2.min.js"></script>
    <script>
        function Delete(id) {
            if (confirm("你确认要删除吗？")) {
                $.ajax({
                    url: "DeleteInfo.ashx",
                    data: { "id": id },
                    type: "post",
                    dataType: "text",
                    success: function (data) {
                        if (data > 0) {
                            alert("删除成功！");
                            location.href = "Default.aspx";
                        }
                        else {
                            alert("删除失败！");
                        }
                    }
                });
            }
        }

        //上架
        function Up(data) {
            $.ajax({
                url: "UpdateState.ashx",
                data: { "id": data },
                type: "post",
                dataType: "text",
                success: function (data) {
                    if (data > 0) {
                        alert("上架失败");
                    }
                    else {
                        alert("上架成功");
                        location.href = "Default.aspx";
                    }

                }
            })
        }
        //下架
        function Down(data) {
            $.ajax({
                url: "UpdateState.ashx",
                data: { "id": data },
                type: "post",
                dataType: "text",
                success: function (data) {
                    if (data > 0) {
                        alert("下架失败");
                    }
                    else {
                        alert("下架成功");
                        location.href = "Default.aspx";
                    }
                }
            })
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <h2>房屋管理</h2>
            小区名称：<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            <asp:Button ID="btnSelectName" runat="server" Text="查询" OnClick="btnSelectName_Click"/>&nbsp&nbsp
            <asp:Button ID="btnAdd" runat="server" Text="添加" OnClick="btnAdd_Click" />
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
                <Columns>
                    <asp:BoundField DataField="Id" HeaderText="房屋编号" />
                    <asp:BoundField DataField="Name" HeaderText="小区名称" />
                    <asp:BoundField DataField="Area" HeaderText="面积" />
                    <asp:BoundField DataField="Price" HeaderText="期望售价" />
                    <asp:BoundField DataField="FloorCount" HeaderText="层数" />
                    <asp:BoundField DataField="Floot" HeaderText="所在楼层" />
                    <asp:TemplateField HeaderText="状态">
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%#Eval("State").ToString()=="1"?"下架":"上架" %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Describe" HeaderText="房屋简介" />
                    <asp:BoundField DataField="Years" HeaderText="年限" />
                    <asp:BoundField DataField="TypeName" HeaderText="房屋类型" />
                    <asp:TemplateField HeaderText="操作">
                        <ItemTemplate>
                            <a href="Update.aspx?id=<%# Eval("Id") %>">编辑</a>
                            <asp:Button ID="Button1" runat="server" Text="上架" OnClientClick='<%# "Up("+Eval("Id")+")" %>' Visible='<%#Eval("State").ToString()=="1" %>' />
                            <asp:Button ID="Button2" runat="server" Text="下架" OnClientClick='<%# "Down("+Eval("Id")+")" %>' Visible='<%#Eval("State").ToString()=="0" %>' />
                            <a href="#" onclick='Delete(<%#Eval("Id") %>)'>删除</a>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
                <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
                <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
                <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
                <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
                <SortedAscendingCellStyle BackColor="#FFF1D4" />
                <SortedAscendingHeaderStyle BackColor="#B95C30" />
                <SortedDescendingCellStyle BackColor="#F1E5CE" />
                <SortedDescendingHeaderStyle BackColor="#93451F" />
            </asp:GridView>
        </div>
    </form>
</body>
</html>
